package com.cornergj.back.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.cornergj.model.Admin;
import com.cornergj.model.Entity;
import com.cornergj.model.Entity.AdminCriteria;
import com.cornergj.model.Entity.FrontImgCriteria;
import com.cornergj.model.Entity.OrderServiceCriteria;
import com.cornergj.model.Entity.Pagination;
import com.cornergj.model.Entity.ServiceContentCriteria;
import com.cornergj.model.Entity.UserQuestionCriteria;
import com.cornergj.model.Entity.Value;
import com.cornergj.model.BranchAddress;
import com.cornergj.model.FrontImg;
import com.cornergj.model.Nanny;
import com.cornergj.model.OrderService;
import com.cornergj.model.ServiceContent;
import com.cornergj.model.UserQuestion;
import com.cornergj.response.ErrorCode;
import com.cornergj.response.JsonResult;
import com.cornergj.service.AdminService;
import com.cornergj.service.FrontImgService;
import com.cornergj.service.NannyService;
import com.cornergj.service.OrderServiceService;
import com.cornergj.service.ServiceContentService;
import com.cornergj.service.UserQuestionService;
import com.cornergj.uitl.FileUtils;


/**
 * Title:
 * Model:
 * Description:
 * @author 郑耿杰
 * @date 2018年1月31日
 */
@Controller
@RequestMapping("/question")
public class QuestionMagementController {
	
	@Autowired
	private ServiceContentService serviceContentService;
	@Autowired
	private UserQuestionService userQuestionService;
	/**
	 * 分页方法
	 * @param request
	 * @param bean
	 * @param pagination
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(HttpServletRequest request, UserQuestion bean, Pagination pagination) {
		//查询条件封装
		UserQuestionCriteria criteria = new UserQuestionCriteria();
		//分页查询
		Pagination list = userQuestionService.selectPage(criteria, pagination);
		
		criteria.setIsread(Value.eq(0));
		List<UserQuestion> questlist=userQuestionService.selectList(criteria);
		for(UserQuestion userQuestion:questlist){
			userQuestion.setIsread(1);
			userQuestionService.update(userQuestion);
		}
		
		request.setAttribute("pagination", list);
		request.setAttribute("bean", bean);
		return "question/list";
	}
	/**
	 * 删除
	 * @param request
	 * @return
	 * @throws IOException 
	 * @throws IllegalStateException 
	 */
	@RequestMapping(value = "/del", method = RequestMethod.GET)
	@ResponseBody
	public JsonResult del(HttpServletRequest request,int qid) throws IllegalStateException, IOException {
		JsonResult jsonResult=new JsonResult();
		try{
			userQuestionService.delete(qid);
		}catch(Exception e){
			e.printStackTrace();
			jsonResult.addErrorCode(ErrorCode.SYS_ERR);
		}
		return jsonResult;
	}
}
